package com.nulldev.util.web.nTube.util.demos;

import com.nulldev.util.JVM.JVM;
import com.nulldev.util.VariableAPI.ByteUtil;
import com.nulldev.util.VariableAPI.RandomUtil;
import com.nulldev.util.io.FastIO.FastIO;
import com.nulldev.util.networking.ip.IP;
import com.nulldev.util.security.encryptAPI_rw.impls.lea.LEACTRCipher;

public class LEACTRUrlizer {

	public static void main(String[] args) {
		final LEACTRCipher des = new LEACTRCipher();
		for (int i = 0; i < 100000; i++) {
			final byte[] key = RandomUtil.bytes(32);
			/* zero'd IV moment */
			final String testString = IP.generateRandomIP();
			final String enc = ByteUtil.getHex(des.encrypt(testString.getBytes(), key));
			final byte[] dec;
			try {
				dec = des.decrypt(ByteUtil.fromHex(enc), key);
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
			final String out = new String(dec);
			if (!IP.isIP(out)) {
				JVM.println("Failed to decrypt an IP! (iteration=" + i + ")");
				JVM.println("key: " + ByteUtil.getHex(key));
				JVM.println("ip: " + testString);
				JVM.println("got: " + new String(dec));
				break;
			}
		}
		JVM.println("Done.");
		FastIO.get().flush();
		JVM.exit();
	}

}
